<template>
  <ConnectDialog
    v-model="visible"
    custom-class="com-dialog-new no-header"
    text="The $JOKER Airdrop is now live!"
    btn-text="Update"
  />
</template>

<script setup>
import { ref, onBeforeMount, onUnmounted, inject, defineEmits } from 'vue'
import ConnectDialog from './ConnectDialog.vue'
import { log } from '../utils/log.js'
import { useCommonStore } from '../stores/index'
const $axios = inject('$axios')
const visible = ref(false)
let version = ''
let timer
const emits = defineEmits(['change'])
const commonStore = useCommonStore()

onBeforeMount(async () => {
  version = await commonStore.getVersion()
  timer = setInterval(async () => {
    const newVersion = await commonStore.getVersion()
    if (version && newVersion && version !== newVersion) {
      visible.value = true
      emits('change')
    } else if (newVersion) {
      version = newVersion
    }
  }, 1000 * 60 * 5)
})

onUnmounted(() => {
  window.clearInterval(timer)
})
</script>
